home *** CD-ROM | disk | FTP | other *** search
/ Aminet 32 / Aminet 32 (1999)(Schatztruhe)[!][Aug 1999].iso / Aminet / biz / haage / WarpUP_V40Upd.lha / WarpUP-WarpOS / PowerUpEmu / tests / msgtestPPC.c < prev    next >
C/C++ Source or Header  |  1999-04-14  |  4KB  |  177 lines

  1. #include <exec/types.h>
  2. #include <exec/nodes.h>
  3. #include <exec/lists.h>
  4. #include <exec/memory.h>
  5. #include <utility/tagitem.h>
  6. #include <powerup/ppclib/interface.h>
  7. #include <powerup/ppclib/message.h>
  8. #define __SASC
  9. #include <powerup/gcclib/powerup_protos.h>
  10. #undef __SASC
  11.  
  12. #define TEXT    "Text sent by PPC processor\n"
  13.  
  14. BPTR    MyFile;
  15. void printf(char *String);
  16.  
  17.  
  18. int main(void)
  19. {
  20.   struct TagItem  MyTags[10];
  21.   void            *PPCPort;
  22.   void            *ReplyPort;
  23.   void            *M68kPort;
  24.   void            *PPCMsg;
  25.   void            *M68kMsg;
  26.   void            *Body;
  27.   ULONG           result;
  28.  
  29. #ifdef DEBUG
  30.   if (MyFile = PPCOpen("con:0/0/640/200/MessageDemo - PPC output/CLOSE", MODE_NEWFILE))
  31.   {
  32.     printf("Creating message port\n");
  33. #endif
  34.     MyTags[0].ti_Tag  = PPCPORTTAG_NAME;
  35.     MyTags[0].ti_Data = (ULONG) "PPC port";
  36.     MyTags[1].ti_Tag  = TAG_DONE;
  37.     if (PPCPort = PPCCreatePort(MyTags))
  38.     {
  39. #ifdef DEBUG
  40.       printf("Waiting for M68k message\n");
  41. #endif
  42.       PPCWaitPort(PPCPort);
  43.  
  44. #ifdef DEBUG
  45.       printf("Getting message\n");
  46. #endif
  47.       if (M68kMsg = PPCGetMessage(PPCPort))
  48.       {
  49. #ifdef DEBUG
  50.         printf("Message: ");
  51.         printf((char*) PPCGetMessageAttr(M68kMsg, PPCMSGTAG_DATA));
  52. #endif
  53.         PPCReplyMessage(M68kMsg);
  54.       }
  55.       else
  56.       {
  57. #ifdef DEBUG
  58.         printf("Did not get m68k msg\n");
  59. #endif
  60.       }
  61.  
  62. #ifdef DEBUG
  63.       printf("Allocating memory for message body\n");
  64. #endif
  65.       if (Body = PPCAllocVec(sizeof(TEXT), MEMF_PUBLIC))
  66.       {
  67. #ifdef DEBUG
  68.         printf("Creating reply port\n");
  69. #endif
  70.         MyTags[0].ti_Tag = TAG_DONE;
  71.         if (ReplyPort = PPCCreatePort(MyTags))
  72.         {
  73. #ifdef DEBUG
  74.           printf("Creating message\n");
  75. #endif
  76.           if (PPCMsg = PPCCreateMessage(ReplyPort, sizeof(TEXT)))
  77.           {
  78. #ifdef DEBUG
  79.             printf("Obtaining M68k port\n");
  80. #endif
  81.             MyTags[0].ti_Tag  = PPCPORTTAG_NAME;
  82.             MyTags[0].ti_Data = (ULONG) "M68k port";
  83.             MyTags[1].ti_Tag  = TAG_DONE;
  84.             while (!(M68kPort = PPCObtainPort(MyTags)));
  85.  
  86. #ifdef DEBUG
  87.             printf("Sending message\n");
  88. #endif
  89.             strcpy(Body, TEXT);
  90.  
  91.             PPCSendMessage(M68kPort,
  92.                            PPCMsg,
  93.                            Body,
  94.                            sizeof(TEXT),
  95.                            0x87654321);
  96.  
  97. #ifdef DEBUG
  98.             printf("Waiting for reply\n");
  99. #endif
  100.             PPCWaitPort(ReplyPort);
  101.  
  102. #ifdef DEBUG
  103.             printf("Releasing M68k port\n");
  104. #endif
  105.             PPCReleasePort(M68kPort);
  106.  
  107. #ifdef DEBUG
  108.             printf("Deleting message\n");
  109. #endif
  110.             PPCDeleteMessage(PPCMsg);
  111.  
  112.           }
  113.           else
  114.           {
  115. #ifdef DEBUG
  116.             printf("Could not create ppc msg\n");
  117. #endif
  118.           }
  119.  
  120. #ifdef DEBUG
  121.           printf("Deleting reply port\n");
  122. #endif
  123.           while (PPCDeletePort(ReplyPort) == FALSE);
  124.  
  125.         }
  126.         else
  127.         {
  128. #ifdef DEBUG
  129.           printf("Could not create reply port\n");
  130. #endif
  131.         }
  132.  
  133. #ifdef DEBUG
  134.         printf("Freeing message body memory\n");
  135. #endif
  136.         PPCFreeVec(Body);
  137.       }
  138.       else
  139.       {
  140. #ifdef DEBUG
  141.         printf("Could not alloc mem for msg body\n");
  142. #endif
  143.       }
  144.  
  145. #ifdef DEBUG
  146.       printf("Deleting message port\n");
  147. #endif
  148.       while (PPCDeletePort(PPCPort) == FALSE)
  149.       {
  150. /*
  151.         PPCRawDoFmt("deleteport failed...\n",
  152.                     NULL,
  153.                     1,        // 0=Buffer,1=serial <> NOT supported yet
  154.                     NULL);
  155. */
  156.       }
  157.     }
  158.     else
  159.     {
  160. #ifdef DEBUG
  161.       printf("Could not create ppc port\n");
  162. #endif
  163.     }
  164.  
  165. #ifdef DEBUG
  166. /*    printf("Closing output\n");
  167.     PPCClose(MyFile);*/
  168.   }
  169. #endif
  170. }
  171.  
  172.  
  173. void printf(char *String)
  174. {
  175.   PPCWrite(MyFile, String, strlen(String));
  176. }
  177.